/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetAllDistributionLists
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public static final String BY_NAME = "name";
/*     */   public static final String BY_ID = "id";
/*     */   
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  47 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  52 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  53 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  55 */     Element response = null;
/*     */     
/*  57 */     Element d = request.getOptionalElement("domain");
/*  58 */     Domain domain = null;
/*     */     
/*  60 */     if (d != null) {
/*  61 */       String key = d.getAttribute("by");
/*  62 */       String value = d.getText();
/*     */       
/*  64 */       if (key.equals("name")) {
/*  65 */         domain = prov.get(Key.DomainBy.name, value);
/*  66 */       } else if (key.equals("id")) {
/*  67 */         domain = prov.get(Key.DomainBy.id, value);
/*     */       } else {
/*  69 */         throw ServiceException.INVALID_REQUEST("unknown value for by: " + key, null);
/*     */       }
/*  71 */       if (domain == null) {
/*  72 */         throw AccountServiceException.NO_SUCH_DOMAIN(value);
/*     */       }
/*     */     }
/*  75 */     if (isDomainAdminOnly(zsc)) {
/*  76 */       if (domain != null) {
/*  77 */         checkDomainRight(zsc, domain, AdminRight.PR_ALWAYS_ALLOW);
/*     */       }
/*  79 */       domain = getAuthTokenAccountDomain(zsc);
/*     */     }
/*     */     
/*  82 */     AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
/*     */     Iterator dit;
/*  84 */     if (domain != null) {
/*  85 */       response = zsc.createElement(AdminConstants.GET_ALL_DISTRIBUTION_LISTS_RESPONSE);
/*  86 */       doDomain(zsc, response, domain, aac);
/*     */     } else {
/*  88 */       response = zsc.createElement(AdminConstants.GET_ALL_DISTRIBUTION_LISTS_RESPONSE);
/*  89 */       List domains = prov.getAllDomains();
/*  90 */       for (dit = domains.iterator(); dit.hasNext();) {
/*  91 */         Domain dm = (Domain)dit.next();
/*  92 */         doDomain(zsc, response, dm, aac);
/*     */       }
/*     */     }
/*  95 */     return response;
/*     */   }
/*     */   
/*     */   private void doDomain(ZimbraSoapContext zsc, Element e, Domain d, AdminAccessControl aac) throws ServiceException {
/*  99 */     List dls = Provisioning.getInstance().getAllGroups(d);
/* 100 */     for (Iterator it = dls.iterator(); it.hasNext();) {
/* 101 */       Group dl = (Group)it.next();
/* 102 */       boolean hasRightToList = true;
/* 103 */       if (dl.isDynamic())
/*     */       {
/* 105 */         hasRightToList = true;
/*     */       } else {
/* 107 */         hasRightToList = aac.hasRightsToList(dl, Rights.Admin.R_listDistributionList, null);
/*     */       }
/*     */       
/* 110 */       if (hasRightToList) {
/* 111 */         GetDistributionList.encodeDistributionList(e, dl, true, false, null, aac.getAttrRightChecker(dl));
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 118 */     relatedRights.add(Rights.Admin.R_listDistributionList);
/* 119 */     relatedRights.add(Rights.Admin.R_getDistributionList);
/*     */     
/* 121 */     notes.add("If the authenticated admin does not have the corresponding list{Entry} right for an entry, the entry is skipped in the getAllXXX/searchXXX/searchDirectoryResponse,  no PERM_DENIED exception will be thrown. Attributes that are not allowed to be get by the authenticated admin will be returned as <a n=\"{attr-name}\" pd=\"1\"/>.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetAllDistributionLists.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */